package fr.umlv.m2.uwp2011.web.client;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.google.gwt.user.client.ui.Composite;

import fr.umlv.m2.uwp2011.service.user.UserDTO;

public class Session {
	/**
	 * The current user.
	 */
	private UserDTO user;

	/**
	 * Map of pages.
	 */
	private Map<String, Composite> mapPages;

	/**
	 * The current page.
	 */
	private String currentPage;

	/**
	 * The parameters.
	 */
	private Map<String, String> parameters;

	/**
	 * The attributes.
	 */
	private Map<String, Serializable> attributes;

	public Session() {
		this.user = new UserDTO();
		this.mapPages = new HashMap<String, Composite>();
		this.currentPage = Application.LOGIN_PAGE;
		this.parameters = new HashMap<String, String>();
		this.attributes = new HashMap<String, Serializable>();
	}

	/**
	 * Sets the current user.
	 * 
	 * @param user
	 *            the current user.
	 */
	public void setUser(UserDTO user) {
		this.user = user;
	}

	/**
	 * Adds a new page (composite).
	 * 
	 * @param key
	 *            the key of the composite.
	 * @param composite
	 *            the page (composite) to add.
	 */
	public void addPage(String key, Composite composite) {
		this.mapPages.put(key, composite);
	}

	/**
	 * Removes a page (composite).
	 * 
	 * @param key
	 *            the key of the composite.
	 */
	public void removePage(String key) {
		this.mapPages.remove(key);
	}

	/**
	 * Sets the current page.
	 * 
	 * @param page
	 *            the current page.
	 */
	public void setCurrentPage(String page) {
		this.currentPage = page;
	}

	/**
	 * Sets current parameters.
	 * 
	 * @param params
	 *            the current parameters.
	 */
	public void setParameters(Map<String, String> parameters) {
		this.parameters = parameters;
	}

	/**
	 * Sets current attributes;
	 * 
	 * @param attributes
	 *            the current attributes.
	 */
	public void setAttributes(Map<String, Serializable> attributes) {
		this.attributes = attributes;
	}

	/**
	 * Gets the current user.
	 * 
	 * @return the current user.
	 */
	public UserDTO getUser() {
		return this.user;
	}

	/**
	 * Gets a page (composite).
	 * 
	 * @param key
	 *            the key of the composite.
	 * @return the composite.
	 */
	public Composite getPage(String key) {
		return this.mapPages.get(key);
	}

	/**
	 * Gets the current page.
	 * 
	 * @return the current page.
	 */
	public String getCurrentPage() {
		return this.currentPage;
	}

	/**
	 * Gets the current parameters.
	 * 
	 * @return the current parameters.
	 */
	public Map<String, String> getParameters() {
		return this.parameters;
	}

	/**
	 * Gets the current attributes.
	 * 
	 * @return the current attributes.
	 */
	public Map<String, Serializable> getAttributes() {
		return this.attributes;
	}
}
